package com.mes.service.manu;

import com.yy.base.common.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;

@Service
public class ProcessService {
	@Autowired
	private Dao dao;
	
	/**
	 * 根据组织机构，工序号，获取工序信息
	 * @param orgId
	 * @param routeNo
	 * @return
	 */
	public Map<String, Object> getOrgProcess(String orgId, int routeNo) {
		String sql = "select p.emes_process_id id, p.name, p.route_no, p.next_route_no, p.M_Warehouse_Id, p.M_Locator_Id, Join_Facilities " +
				"		,p.PREPARE_TIME " +
				"       ,(select t.name from emes_process t " +
				"          where t.emes_process_route_id=p.emes_process_route_id" +
				"			     and t.route_no=p.next_route_no) next_process_name " +
				"  from Emes_Process p, Emes_Process_Route pr " +
				" where p.Emes_Process_Route_id = pr.Emes_Process_Route_id " +
				"	and p.route_no = ? " +
				"	and pr.ad_org_Id = ?";
		Map<String, Object> map = dao.queryUnique(sql, routeNo, orgId);
		if (map == null) {
			throw new RuntimeException("当前车间未找到" + routeNo + "工序！");
		}
		return map;
	}
	/**
	 * 工序ID获取工序信息
	 * @param processId
	 * @return
	 */
	public Map<String, Object> getProcessInfo(String processId) {
		String sql = "select p.emes_process_id id, p.name, p.route_no, p.next_route_no," +
				"   (select t.emes_process_id from Emes_Process t where t.emes_process_route_id=p.emes_process_route_id " + 
				"           and t.next_route_no=p.route_no) pre_process_id, " + 
				"   (select t.route_no from Emes_Process t where t.emes_process_route_id=p.emes_process_route_id " + 
				"           and t.next_route_no=p.route_no) pre_route_no" +
				"  from Emes_Process p where p.Emes_Process_id = ?";
		return dao.queryUnique(sql, processId);
	}
}